package com.olddriver.crm.web.controller;

import com.olddriver.crm.annotation.PermissionName;
import com.olddriver.crm.domain.Compensation;
import com.olddriver.crm.page.PageResult;
import com.olddriver.crm.query.CompensationQueryObject;
import com.olddriver.crm.service.ICompensationService;
import com.olddriver.crm.util.JsonResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("compensation")
public class CompensationController {

    @Autowired
    private ICompensationService compensationService;

    @RequestMapping("list")
    @RequiresPermissions("compensation:list")
    @PermissionName("查看理赔")
    public String list() {
        return "compensation/list";
    }

    @ResponseBody
    @RequestMapping("query")
    @RequiresPermissions("compensation:query")
    @PermissionName("理赔列表")
    public PageResult query(CompensationQueryObject qo) {
        PageResult result = compensationService.query(qo);
        return result;
    }

   @ResponseBody
   @RequestMapping("saveOrUpdate")
   @RequiresPermissions("compensation:saveOrUpdate")
   @PermissionName("理赔编辑")
   public JsonResult saveOrUpdate(Compensation compensation,String sn) {
       Long id = compensation.getId();
       try {
           if (id != null) {
               compensationService.updateByPrimaryKey(compensation);
           } else {
               compensationService.insert(compensation);
           }
           return JsonResult.success();
       } catch (Exception e) {
           e.printStackTrace();
           return JsonResult.faliure();
       }
   }
    @ResponseBody
    @RequestMapping("delete")
    @RequiresPermissions("compensation:delete")
    @PermissionName("删除理赔")
    public JsonResult delete(Long id) {
        try {
            compensationService.deleteByPrimaryKey(id);
            return JsonResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.faliure();
        }

    }
}
